package com.ucombuy.coupon.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * Created by yaosheng on 2019/12/29.
 * 商品类型枚举
 */
@Getter
@AllArgsConstructor
public enum GoodsType {

    WENYU("文娱", 1),
    SHENGXIAN("生鲜", 2),
    JIAJU("家居", 3),
    OTHERS("其他", 4),
    ALL("全品类", 5);

    //商品类型描述
    private String description;
    //商品类型编码
    private Integer code;

    //根据商品编码获取相应的商品描述信息
    public static GoodsType of(Integer code) {

        Objects.requireNonNull(code);
        return Stream.of(values()).filter(bean -> bean.code.equals(code)).findAny()
                .orElseThrow(() -> new IllegalArgumentException(code + " not exists!")        //非法参数异常
                );
    }
}